package arithmetic;

/**
 * 给定一字符串，里面有些字符有连续出现的特点，
 * 寻找字符串中连续的最长子串，且子串内的字符都不重复，如果最长的子串存在多个，则获取ascii码最小的那一个
 */
public class TestLC1 {
    public static void main(String[] args) {
        String str = "12fffda23";
        String[] strs = test(str);
        test2(strs);
    }

    public static String[] test(String str){
        String[] strs = new String[str.length()];
        int indexArr = 0;
        String str2 = "";
        char[] chs = str.toCharArray();
        for (int i = 0; i < chs.length; i++) {
            int index = str2.indexOf(chs[i]);
            if(index<0){
                str2+=chs[i];
            }else{
                str2 = str2.substring(index+1)+chs[i];
            }
            strs[indexArr] = str2;
            indexArr+=1;
        }
        return strs;
    }

    public static void test2(String[] strs){
        String str = "";
        if (strs.length == 1) System.out.println(strs[0]);
        int i = 0;
        while (i < strs.length){
            int len1 = str.length();
            int len2 = strs[i].length();
            if(len1 == len2 && str.compareTo(strs[i])>0){
                str = strs[i];
            }
            if(len1<len2){
                str = strs[i];
            }
            i++;
        }
        System.out.println(str);
    }

}
